package com.hu.boot.service.impl;

import com.hu.boot.entity.User;
import com.hu.boot.mapper.UserMapper;
import com.hu.boot.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    // 声明一个日志对象
    private static final Logger log = LoggerFactory.getLogger(UserService.class);

    private UserMapper userMapper;

    @Autowired
    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public List<User> findAll() {
        log.debug("测试日志");
        log.debug("查询语句执行开始");
        List<User> userList = this.userMapper.findAll();
        log.debug("查询语句执行结束");
        // 日志的占位符写法
        log.debug("INFO {} ==> {}", "参数1", "参数2");
        return userList;
    }

    @Override
    @Transactional
    public void save(User user) {
        this.userMapper.save(user);
    }

}
